﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WeChatApp.Repositories;
using Newtonsoft.Json;

namespace WeChatApp.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : BaseController
    {
        // GET api/values
        [HttpGet]
        public string Get()
        {
            string url = "https://localhost:44374/api/PostTest";
            string Method = "post";
            string postData = "{ id: \"1\", value: \"Jim\" }";
            var ret = UrlQueryHelper(url, postData, Method);
            return ret;
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id, string name)
        {
            var zr = RepositoryFactoryInst.GetRepository<ValuesRepository>().GetValue();
            return zr;
        }

        // POST api/values
        [HttpPost]
        public JsonResult Post([FromBody] dynamic stu)
        {
            string str = "name=" + stu.name + ",age=" + stu.age;
            return JsonResultHelper(true, str);
        }


        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
    public class Student
    {
        public string name { get; set; }
        public string age { get; set; }
    }
}
